/****************************************************
 * @class DocSearchPanel
 * @extends Ext.grid.GridPanel
 ***************************************************/
	DocSearchPanel = Ext.extend(Ext.grid.GridPanel,{
		condition: null,
		store: null,
		cm: null,
		searchField: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.condition = {};
			this.condition.limit = 50;
			
			this.store = new Ext.data.Store({
			    baseParams: this.condition,   
				proxy: new Ext.data.HttpProxy({
					method: 'POST',
					url: '/pdm/category/getAllDocList.htm'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalProperty',
					root: 'root',
					id: 'doc_id'
				},[
					{name: 'doc_id'},
					{name: 'tmpl_id'},
					{name: 'masterIns_id'},
					{name: 'docName'},
					{name: 'dateOfCreate'},
					{name: 'projectName'},
					{name: 'derivativeName'},
					{name: 'size'},
					{name: 'owner'},
					{name: 'stage'},
					{name: 'status'}
				])
			});
			this.cm = new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
		        {
		           header: "尺寸",
		           dataIndex: 'size',
		           align: 'left',
		           sortable: true,
		           width: 70
	        	},{
		           header: "专案名称",
		           dataIndex: 'projectName',
		           hidden: false,
		           sortable: true,
		           width: 100
		        },{
		           header: "衍生计划名称",
		           dataIndex: 'derivativeName',
		           sortable: true,
		           width: 70
		        },{
		           header: "现行阶段名",
		           dataIndex: 'stage',
		           align: 'left',
		           sortable: true,
		           width: 120
	        	},{
		           header: "文件名称",
		           dataIndex: 'docName',
		           sortable: true,
		           width: 180
		        },{
		           header: "负责人",
		           dataIndex: 'owner',
		           align: 'left',
		           sortable: true,
		           width: 120
	        	},{
		           header: "起案日期",
		           dataIndex: 'dateOfCreate',
		           sortable: false,
		           width: 120
		        },{
		           header: "完成状况",
		           dataIndex: 'status',
		           align: 'left',
		           sortable: true,
		           width: 120
	        	}]);
	        
	        this.store.load();
	        
			this.searchField = new Ext.ux.form.SearchField({store: this.store,width:200});
			
			DocSearchPanel.superclass.constructor.call(this, {
				id: 'docSearchPanel',
			    loadMask: {msg:'Loading...'},
			    viewConfig: {forceFit: true},
				region: 'center',
				border: false,
				height: 500,
				layout: 'fit',
				split: true,
				cls: 'x-rb',
				ds: this.store,
				sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
				cm: this.cm,
				trackMouseOver: false,
				tbar: ["文档查询：",this.searchField],
				fbar: new Ext.PagingToolbar({
					pageSize: 50,
					store: this.store,
					displayInfo: true,
					displayMsg: '显示第 {0}~{1} 条，共 {2} 条记录',
					emptyMsg: "没有记录",
					refreshText: '刷新',
					beforePageText: '第',
					afterPageText: '页，共 {0} 页',
					firstText: '第一页',
					prevText: '前一页',
					nextText: '后一页',
					lastText: '最后一页'
				})
			});
			
			this.on("rowdblclick", function(grid,rowIndex,e){
				var row = grid.getSelectionModel().getSelected();
				var tmpl_id = row.get("tmpl_id");
				var masterIns_id = row.get("masterIns_id");
				if(masterIns_id == "0")
				{
					alert("系统存在问题");
				}
				else if(tmpl_id=="0"){
					alert("未分配模板");
				}
				else{
					window.open("AutoCreate.jsp?mast_id="+masterIns_id+"&tmpl_id="+tmpl_id, "", "height=600px, width=800px, toolbar=no, menubar=yes, scrollbars=yes, resizable=yes, status=yes");
				}
				
			});
		}
	});
	
/****************************************************
 * @class AdvanceSearchPanel
 * @extends Ext.grid.GridPanel
 ***************************************************/
	AdvanceSearchPanel = Ext.extend(Ext.grid.GridPanel, {
		condition: null,
		store: null,
		cm: null,
		searchField: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.condition = {projectName:"", deriveName:"", stage:"", docName:"", owner:"", docName: ""};
			this.condition.limit = 50;
			this.store = new Ext.data.Store({
			    baseParams: this.condition,   
				proxy: new Ext.data.HttpProxy({
					method: 'POST',
					url: '/pdm/category/advancedDocSearch.htm'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalProperty',
					root: 'root',
					id: 'doc_id'
				},[
					{name: 'doc_id'},
					{name: 'tmpl_id'},
					{name: 'masterIns_id'},
					{name: 'docName'},
					{name: 'dateOfCreate'},
					{name: 'projectName'},
					{name: 'deriveName'},
					{name: 'size'},
					{name: 'owner'},
					{name: 'stage'},
					{name: 'status'}
				])
			});
			
			this.cm = new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
		        {
		           header: "尺寸",
		           dataIndex: 'size',
		           align: 'left',
		           sortable: true,
		           width: 70
	        	},{
		           header: "专案名称",
		           dataIndex: 'projectName',
		           hidden: false,
		           sortable: true,
		           width: 100
		        },{
		           header: "衍生计划名称",
		           dataIndex: 'deriveName',
		           sortable: true,
		           width: 70
		        },{
		           header: "现行阶段名",
		           dataIndex: 'stage',
		           align: 'left',
		           sortable: true,
		           width: 120
	        	},{
		           header: "文件名称",
		           dataIndex: 'docName',
		           sortable: true,
		           width: 180
		        },{
		           header: "负责人",
		           dataIndex: 'owner',
		           align: 'left',
		           sortable: true,
		           width: 120
	        	},{
					header: "起案日期",
					dataIndex: 'dateOfCreate',
					sortable: false,
					width: 120
		        },{
					header: "完成状况",
					dataIndex: 'status',
					align: 'left',
					sortable: true,
					width: 120,
					renderer: function(v,m){
						if(v=="[100] Unstarted") m.css = 'x-grid-status-ux-gray';
						else if(v=="[500] On-Going") m.css = 'x-grid-status-ux-yellow';
						else if(v=="[800] Delayed") m.css = 'x-grid-status-ux-red';
						else if(v=="[900] Released"||v=="[910] Closed") m.css = 'x-grid-status-ux-green';
						return v;
					}
	        	}]);
			//this.store.load();
			this.searchField = new Ext.ux.form.SearchField({store: this.store, width:200});
			
			AdvanceSearchPanel.superclass.constructor.call(this, {
				id: 'advanceSearchPanel',
			    loadMask: {msg:'Loading...'},
			    viewConfig: {forceFit: true},
				region: 'center',
				border: false,
				height: 500,
				layout: 'fit',
				split: true,
				cls: 'x-rb',
				ds: this.store,
				sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
				cm: this.cm,
				trackMouseOver: false,
				tbar: ["专案:",{
					xtype: 'textfield',
					id: 'projectName',
					name: 'projectName',
					width: 80,
					emptyText: 'eg: N1401'
				},"版本:",{
					xtype: 'textfield',
					id: 'deriveName',
					name: 'deriveName',
					width: 50,
					emptyText: 'eg: R0'
				},"阶段:",{
					xtype: 'textfield',
					id: 'stage',
					name: 'stage',
					width: 80,
					emptyText: 'eg: EVT'
				},"负责人:",{
					xtype: 'textfield',
					id: 'owner',
					name: 'owner',
					width: 80
				},"文档:",{
					xtype: 'textfield',
					id: 'documentName',
					name: 'documentName',
					width: 120
				},{
					xtype: 'tbspacer',
					width: 15
				},{
					id: 'btn_search',
					text: "查询",
					iconCls: 'cls_toolbar_search',
					ctCls: 'x-btn-over',
					handler: function(){
						var projectName = Ext.fly("projectName").dom.value;
						if(projectName=='eg: N1401') projectName = "";
						
						var deriveName = Ext.fly("deriveName").dom.value;
						if(deriveName == 'eg: R0') deriveName = "";
						
						var stage = Ext.fly("stage").dom.value;
						if(stage=='eg: EVT') stage = "";
						
						var owner = Ext.fly("owner").dom.value;
						var docName = Ext.fly("documentName").dom.value;
						
						var con = {};
						con.projectName = projectName;
						con.deriveName = deriveName;
						con.stage = stage;
						con.owner = owner;
						con.docName = docName;
						
						var advanceSearchPanel = Ext.getCmp("advanceSearchPanel");
						advanceSearchPanel.load(con);
					}
				},'->',{
					text: "数据导出",
					scope: this,
					iconCls: 'cls_excel',
					ctCls: 'x-btn-over',
					hidden: (roleName=="user"),
					tooltip: "导出数据到Excel",
					handler: function(){
						if(this.store.getCount()==0){
							Ext.Msg.alert("提示","没有需要导出的数据");
						}else{
							var projectName = Ext.fly("projectName").dom.value;
							if(projectName=='eg: N1401') projectName = "";
							
							var deriveName = Ext.fly("deriveName").dom.value;
							if(deriveName == 'eg: R0') deriveName = "";
							
							var stage = Ext.fly("stage").dom.value;
							if(stage=='eg: EVT') stage = "";
							
							var owner = Ext.fly("owner").dom.value;
							var docName = Ext.fly("documentName").dom.value;
													
							window.location = window.basePath+"category/exportResult.htm?projectName=" + projectName
			            						+"&deriveName=" + deriveName
			            						+"&stage=" + stage
			            						+"&docName=" + docName
			            						+"&owner=" + owner;
			            	
						
						}
					}
				}],
				bbar: new Ext.PagingToolbar({
					pageSize: 50,
					store: this.store,
					displayInfo: true,
					displayMsg: '显示第 {0}~{1} 条，共 {2} 条记录',
					emptyMsg: "没有记录",
					refreshText: '刷新',
					beforePageText: '第',
					afterPageText: '页，共 {0} 页',
					firstText: '第一页',
					prevText: '前一页',
					nextText: '后一页',
					lastText: '最后一页'
				})
			});
			
			this.on("rowdblclick", function(grid,rowIndex,e){
				var row = grid.getSelectionModel().getSelected();
				var tmpl_id = row.get("tmpl_id");
				var masterIns_id = row.get("masterIns_id");
				if(masterIns_id == "0") Ext.Msg.alert("异常消息","系统存在问题，请联系管理员");
				else if(tmpl_id=="0") Ext.Msg.alert("提示","未分配模板，请联系管理员");
				else{
					window.open("AutoCreate.jsp?mast_id="+masterIns_id+"&tmpl_id="+tmpl_id, "", "height=600px, width=800px, toolbar=no, menubar=yes, scrollbars=yes, resizable=yes, status=yes");
				}
			});
		},
		load: function(con){
			this.condition.limit = 50;
			this.condition.projectName = con.projectName;
			this.condition.deriveName = con.deriveName;
			this.condition.stage = con.stage;
			this.condition.owner = con.owner;
			this.condition.docName = con.docName;
			
			this.store.load();
		}
	});
	